/**
 * @description 使用该mixin需要在table组件上添加style: "height: calc(100% - 42px);"
 * 保证table自适应高度留出分页器的空间
 */
const mixin = {
  data() {
    return {
      pagination: {
        pageNo: 1,
        pageSize: 10,
        totalCount: 0
      }
    }
  },
  mounted() {
    this.updateList()
  },
  methods: {
    updateList() {
      const { totalCount, pageNo, pageSize } = this.pagination
      if (totalCount > 0 && pageNo > Math.ceil(totalCount / pageSize)) {
        return
      }
      // 该函数需要在使用此mixin的组件中定义
      this.getList({
        ...this.searchForm,
        pageNo,
        pageSize
      })
    },

    /* sec-pagination组件事件回调函数 start */
    // 每页数据量变化触发事件函数
    handleSizeChange(val) {
      this.pagination.pageSize = val
      this.updateList()
    },
    // 翻页触发事件函数
    handleCurrentChange(val) {
      this.pagination.pageNo = val
      this.updateList()
    },
    /* end */

    /* custom-search组件事件回调函数 start */
    resetFn() {
      this.searchForm = {}
      this.evtTime = []
      this.pagination = {
        pageNo: 1,
        pageSize: 10,
        totalCount: 0
      }
      this.getList()
    },
    searchFn() {
      this.getList({
        ...this.searchForm,
        // _updatedAt: Date.now(),
        pageNo: 1,
        pageSize: this.pagination.pageSize
      })
    }
    /* end */
  }
}
export default mixin
